﻿<!DOCTYPE HTML>
<html xmlns:th="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
	<script src="../../static/js/jquery-3.5.1.min.js" th:src="@{/js/jquery-3.5.1.min.js}"></script>
<link rel="stylesheet" type="text/css" href="../../static/h-ui/css/H-ui.min.css" th:href="@{/h-ui/css/H-ui.min.css}"/>
<link rel="stylesheet" type="text/css" href="../../static/h-ui.admin/css/H-ui.admin.css" th:href="@{/h-ui.admin/css/H-ui.admin.css}"/>
<link rel="stylesheet" type="text/css" href="../../static/lib/Hui-iconfont/1.0.8/iconfont.css" th:href="@{/lib/Hui-iconfont/1.0.8/iconfont.css}"/>
<link rel="stylesheet" type="text/css" href="../../static/h-ui.admin/skin/default/skin.css" id="skin" th:href="@{/h-ui.admin/skin/default/skin.css}"/>
<link rel="stylesheet" type="text/css" href="../../static/h-ui.admin/css/style.css" th:href="@{/h-ui.admin/css/style.css}"/>
<link rel="stylesheet" href="../../static/Semantic-UI-master/dist/semantic.min.css" th:href="@{/Semantic-UI-master/dist/semantic.min.css}">
<link rel="stylesheet" href="../../static/css/custom.css" th:href="@{/css/custom.css}">
<title>课程管理</title>
</head>
<script type="text/javascript" th:inline="javascript">
	$(function () {
		if(![[${session.admin}]]){
			alert("请先去登录")
			window.location.replace("/sy/syadmin/admin")
		}
	})

</script>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 课程管理 <span class="c-gray en">&gt;</span> 课程管理 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
	<div class="text-c m-padded-t-middle">
		<!------------------------------           搜索栏TOP----------------------------------------->
		<div class="" style="padding-bottom: 10px">
			<input class="searchinput1 prompt" type="text" id="searchinput" placeholder="课程搜索......">
			<button class="searchbutton1 ui teal button" id="searchbutton"><i class="search icon"></i></button>
		</div>
		<!------------------------------           搜索栏END----------------------------------------->
	</div>

	<div class="cl pd-5 bg-1 bk-gray mt-20">
		<span class="l">
			<a class="btn btn-primary radius" onclick="picture_add('课程发布','/sy/course/courseadd?userId=')"
			   href="javascript:;"><i class="Hui-iconfont">&#xe600;</i> 去发布课程</a>

		</span>
		<span class="r">共有数据：<strong id="datanum" th:text="${session.courseadmin.size()}"></strong> 条</span> </div>
	<div class="mt-20" id="searchtext">
		<table class="table table-border table-bordered table-bg table-sort">
			<thead>
				<tr class="text-c">
					<th width="70">ID</th>
					<th width="120">课程名称</th>
					<th width="70">发布者</th>
					<th width="160">课程简介</th>
					<th width="70">用户/管理员</th>
					<th width="90">封面图片</th>
					<tH width="120">操作</tH>
				</tr>
			</thead>
			<tbody id="searchshow">
				<tr class="text-c" th:each="course:${session.courseadmin}">
					<td th:text="${course.courseId}">1</td>
					<td th:text="${course.courseName}">操作系统</td>
					<td th:text="${course.courseAuthor}">sytset</td>
					<td class="text-l" th:text="${course.courseDetails}">
						操作系统_清华大学(向勇、陈渝) https://github.com/chyyuu/os_course_info
					</td>

					<td class="text-l" th:if="${course.courseAuid}==0">管理员</td>
					<td class="text-l" th:unless="${course.courseAuid}==0">教师</td>
					<td><img style="width: 100px;height: auto;" th:src="${course.courseImge}"></td>
					<td class="f-14 product-brand-manage courseadmin">
						<a style="text-decoration:none" th:onClick="course_list('教学视频','',[[${course.courseId}]])" href="javascript:;" title="教学视频">课件</a>
						<a style="text-decoration:none" th:onClick="homework('课程作业','',[[${course.courseId}]])" href="javascript:;" title="课程作业">作业</a>
						<a style="text-decoration:none" th:onClick="course_edit('课程编辑','',[[${course.courseId}]])" href="javascript:;" title="编辑"><i class="Hui-iconfont">&#xe6df;</i></a>
						<a style="text-decoration:none" class="ml-5" th:onClick="course_del(this,[[${course.courseId}]])" href="javascript:;" title="删除"><i class="Hui-iconfont">&#xe6e2;</i></a>
					</td>
				</tr>

			</tbody>
		</table>
	</div>
</div>
<!--_footer 作为公共模版分离出去-->

<script type="text/javascript" src="../../static/lib/layer/2.4/layer.js" th:src="@{/lib/layer/2.4/layer.js}"></script>
<script type="text/javascript" src="../../static/h-ui/js/H-ui.min.js" th:src="@{/h-ui/js/H-ui.min.js}"></script>
<script type="text/javascript" src="../../static/h-ui.admin/js/H-ui.admin.js" th:src="@{/h-ui.admin/js/H-ui.admin.js}"></script> <!--/_footer 作为公共模版分离出去-->
<script src="../../static/js/jquery-ui.min.js" th:src="@{/js/jquery-ui.min.js}"></script>
<script src="../../static/Semantic-UI-master/dist/semantic.min.js" th:src="@{/Semantic-UI-master/dist/semantic.min.js}"></script>
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="../../static/lib/laypage/1.2/laypage.js" th:src="@{/lib/laypage/1.2/laypage.js}"></script>
<script type="text/javascript">

	//搜索
	$("#searchbutton").click(function () {
		var text = $("#searchinput").val();
		$.ajax({
			type: "get",
			cache: false,
			url: "/sy/course/search",
			data: {"searchstr":text},
			contenType: "application/json;charset=utf-8",
			success: function (data) {


				if(data.length==0){
                    layer.msg('没有搜索到内容',{icon:0,time:2000});
				}else {
                    $("#datanum").text(data.length);
					var htmls = '';

					for(let i=0; i<data.length; i++){
						var aaa = '';
						if(data[i].courseAuid==0) aaa='管理员'
						else aaa='教师'
						var add ='<tr class="text-c">\n' +
                            '<td>'+data[i].courseId+'</td>\n' +
                            '<td>'+data[i].courseName+'</td>\n' +
                            '<td>'+data[i].courseAuthor+'</td>\n' +
                            '<td class="text-l">'+data[i].courseDetails+'</td>\n' +
                            '<td class="text-l" >'+aaa+'</td>\n' +
                            '<td><img style="width: 100px;height: auto;" src="'+data[i].courseImge+'"></td>\n' +
                            '<td class="f-14 product-brand-manage courseadmin">\n' +
                            '<a style="text-decoration:none" onClick="course_list(\'教学视频\',\'\','+data[i].courseId+')" href="javascript:;" title="教学视频">课件</a>\n' +
                            '<a style="text-decoration:none" onClick="homework(\'课程作业\',\'\','+data[i].courseId+')" href="javascript:;" title="课程作业">作业</a>\n' +
                            '<a style="text-decoration:none" onClick="course_edit(\'课程编辑\',\'\','+data[i].courseId+')" href="javascript:;" title="编辑"><i class="Hui-iconfont">&#xe6df;</i></a>\n' +
                            '<a style="text-decoration:none" class="ml-5" onClick="course_del(this,'+data[i].courseId+')" href="javascript:;" title="删除"><i class="Hui-iconfont">&#xe6e2;</i></a>\n' +
                            '</td>\n' +
                            '</tr>';


						htmls += add;
					}
					$("#searchshow").html(htmls);
				}
			},
			error: function (message) {
				layer.msg('出错了',{icon:0,time:1000});
			}
		})

	})




	/*课程-添加*/
	function picture_add(title,url){
		var index = layer.open({
			type: 2,
			title: title,
			content: url+0
		});
		layer.full(index);
	}
	/*课程-编辑*/
	function course_edit(title,url,id,w,h){
		$.ajax({
			Type: 'get',
			cache: false,
			url: '/sy/course/goEditorCourse',
			data: {'courseid':id},
			contenType: 'application/json;charset:utf-8',
			success: function(data){
				layer_show(title,data,w,h);
			},
			error:function(data) {
				layer.msg('出错了',{icon:0,time:1000});
			},
		})
	}
	//课件列表
	function course_list(title,url,id,w,h){
		$.ajax({
			Type: 'get',
			cache: false,
			url: '/sy/video/videoList',
			data: {'courseid':id},
			contenType: 'application/json;charset:utf-8',
			success: function(data){
				layer_show(title,data,w,h);
			},
			error:function(data) {
				layer.msg('出错了',{icon:0,time:1000});
			},
		})

	}
	//作业
	function homework(title,url,id,w,h){
		$.ajax({
			Type: 'get',
			cache: false,
			url: '/sy/homework/homeworkList',
			data: {'courseid':id},
			contenType: 'application/json;charset:utf-8',
			success: function(data){
				layer_show(title,data,w,h);
			},
			error:function(data) {
				layer.msg('出错了',{icon:0,time:1000});
			},
		})
	}
	/*课程-删除*/
	function course_del(obj,id){
		layer.confirm('确认要删除吗？',function(index){
			$.ajax({
				type: 'POST',
				url: '/sy/course/deletecourse',
				cache: false,
				data: {'courseId':id},
				success: function(data){
					$(obj).parents("tr").remove();
					layer.msg('已删除!',{icon:1,time:1000});
				},
				error:function(data) {
					layer.msg('出错了',{icon:0,time:1000});
				},
			});
		});
	}
</script>
</body>
</html>